//
//  Teacher.m
//  RepasoApp
//
//  Created by Vicente Vicens Camarena on 02/10/11.
//  Copyright 2011 Imathink World, S.L.N.E. All rights reserved.
//

#import "Teacher.h"
#import "Course.h"

@implementation Teacher

@synthesize teacherId = teacherId_;
@synthesize teacherName = teacherName_;
@synthesize teacherCourses = teacherCourses_;

//Designated initializer
- (id)initWithDictionary:(NSDictionary *)dictionary
{
    self = [super init];
    if (self) {
        // Initialization code here.
        self.teacherId = [dictionary objectForKey:@"teacher_id"];
        self.teacherName = [dictionary objectForKey:@"teacher_name"];
        self.teacherCourses = [NSMutableArray array];
        for (NSDictionary *teacherDictionary in [dictionary objectForKey:@"teacher_courses"]) {
            [self.teacherCourses addObject:[Course courseWithDictionary:teacherDictionary]];
        }
    }
    
    return self;
}

- (id)init
{
    return [self initWithDictionary:nil];
}

+ (Teacher *)teacherWithDictionary:(NSDictionary *)dictionary {
    return [[[Teacher alloc] initWithDictionary:dictionary] autorelease];
}

- (void)dealloc {
    [teacherId_ release];
    [teacherName_ release];
    [teacherCourses_ release];
    [super dealloc];
}

@end
